package com.mihu.stmall.manager.controller.api;


import com.mihu.stmall.manager.entiy.Result;
import com.mihu.stmall.manager.util.UploadUtil;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

@RestController
@RequestMapping("/api/upload")
public class APIUploadController {
    @Value("${upload.path}")
    //使用SPring的EL表达式 读取配置文件 upload属性的值
    private String path;

    //上传文件的操作应该使用POST

    @PostMapping
    public Result upload(MultipartFile file){
        String fileName = UploadUtil.save(file,path);
        if (fileName != null) {
            return Result.success(fileName);
        }else {
            return Result.error("上传失败");
        }

    }

}
